import {combineReducers} from 'redux-immutable';
import * as actions from './actions';
import Immutable from 'immutable';
import {DEFAULT_QUERY_OPTION} from './constants';
const list = (state, action) => {
    switch(action.type) {
        case actions.GET_LIST_DATA_BEGIN:
            return state.merge({
                isFetching: true,
                hasError: '',
            });
        case actions.GET_LIST_DATA_SUCCESS:
            return state.merge({
                isFetching: false,
                hasError: '',
                data: action.data
            });
        case actions.GET_LIST_DATA_FAIL:
            return state.merge({
                isFetching: false,
                data: {},
                hasError: action.message,
            });
        default:
            return state;
    }
};
const listType = (state, action) => {
    switch(action.type) {
        case actions.GET_LIST_TYPE_BEGIN:
            return state.merge({
                isFetching: true,
                hasError: '',
            });
        case actions.GET_LIST_TYPE_SUCCESS:
            return state.merge({
                isFetching: false,
                hasError: '',
                data: action.data
            });
        case actions.GET_LIST_TYPE_FAIL:
            return state.merge({
                isFetching: false,
                data: [],
                hasError: action.message,
            });
        default:
            return state;
    }
};
const listRate = (state, action) => {
    switch(action.type) {
        case actions.GET_LIST_RATE_BEGIN:
            return state.merge({
                isFetching: true,
                hasError: '',
            });
        case actions.GET_LIST_RATE_SUCCESS:
            return state.merge({
                isFetching: false,
                hasError: '',
                data: action.data
            });
        case actions.GET_LIST_RATE_FAIL:
            return state.merge({
                isFetching: false,
                data: [],
                hasError: action.message,
            });
        default:
            return state;
    }
};
const appState = (state, action) => {
    switch(action.type) {
        case actions.SAVE_QUERY_DEALER:
            return state.set('queryDealer', action.data);
        case actions.SAVE_QUERY_CONDITION:
            return state.setIn(['queryCondition', action.name], action.value);
        case actions.RESET_QUERY_PANEL:
            return state.set('queryCondition', Immutable.fromJS(DEFAULT_QUERY_OPTION));
        default:
            return state;
    }
};
const domainData = combineReducers({
    list,
    listType,
    listRate
});

export default combineReducers({
    domainData,
    appState,
});
